package org.jeecg.modules.gwcjava.jiekou.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.gwcjava.jiekou.entity.*;
import org.jeecg.modules.gwcjava.jiekou.mapper.MlccUserInfoMapper;
import org.jeecg.modules.gwcjava.jiekou.service.MlccUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MlccUserInfoServiceImpl extends ServiceImpl<MlccUserInfoMapper, MlccUserInfo> implements MlccUserInfoService {
    @Autowired
    private MlccUserInfoMapper userInfoMapper;

    /**根据用户名查询用户*/
    @Override
    public MlccUserInfo queryUserinfoByusername(String username,int type) {
        MlccUserInfo userInfo = userInfoMapper.queryUserinfoByusername(username,type);
        return userInfo;
    }

    /**根据条件去修改用户的token*/
    @Override
    public int update_token(String token, String quername, int type) {
        try {
            userInfoMapper.update_token(token, quername,type);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("修改token失败"+e);
            return 0;
        }
    }
    /**新增员工*/
    @Override
    public int insert_userinfo(WebUserinfo userInfo) {
        try {
            userInfoMapper.insert_userinfo(userInfo);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("新增失败"+e);
            return 0;
        }
    }
    /**编辑员工*/
    @Override
    public int update_userinfo(WebUserinfo userInfo) {
        try {
            userInfoMapper.update_userinfo(userInfo);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("编辑失败"+e);
            return 0;
        }
    }

    //修改用户信息根据条件
    @Override
    public int update_userinfoById(WebUserinfo userInfo) {
        try {
            userInfoMapper.update_userinfoById(userInfo);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("编辑失败"+e);
            return 0;
        }
    }
    //更换手机号
    @Override
    public int change_phone(WebUserinfo userInfo) {
        try {
            userInfoMapper.change_phone(userInfo);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("编辑失败"+e);
            return 0;
        }
    }
    //更换用户名
    @Override
    public int change_user_realname(WebUserinfo userInfo) {
        try {
            userInfoMapper.change_user_realname(userInfo);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("编辑失败"+e);
            return 0;
        }
    }

    //根据公司id查询公司信息
    @Override
    public CompanyInfo queryCompanyinfoById(String companyId) {
        CompanyInfo datainfo = userInfoMapper.queryCompanyinfoById(companyId);
        return datainfo;
    }
    //根据公司id查询所有门店信息
    @Override
    public List<StoreInfo> queryAllStoreinfoById(String companyId) {
        List<StoreInfo> datalist = userInfoMapper.queryAllStoreinfoById(companyId);
        return datalist;
    }
    //根据公司id查询所有用户信息
    @Override
    public List<MlccUserInfo> queryAllUserinfoById(String companyId) {
        List<MlccUserInfo> datalist = userInfoMapper.queryAllUserinfoById(companyId);
        return datalist;
    }
    //先创建充值订单
    @Override
    public int create_chargeOrder(ChargeOrderInfo chargeOrderInfo) {
        try {
            userInfoMapper.create_chargeOrder(chargeOrderInfo);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("编辑失败"+e);
            return 0;
        }
    }
    //根据充值订单流水号查询（已充值就修改用户余额）
    @Override
    public ChargeOrderInfo queryChargeOrderInfo(String charge_sn) {
        ChargeOrderInfo datainfo = userInfoMapper.queryChargeOrderInfo(charge_sn);
        return datainfo;
    }

    @Override
    public int update_chargeOrder_status(String id, String status) {
        try {
            userInfoMapper.update_chargeOrder_status(id,status);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("编辑失败"+e);
            return 0;
        }
    }

    //修改用户余额
    @Override
    public int update_user_balance(String money,String user_id) {
        try {
            userInfoMapper.update_user_balance(money,user_id);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("编辑失败"+e);
            return 0;
        }
    }
    //插入财务流水表
    @Override
    public int insert_financial(String user_id, String financial_number, String financial_details, String single_money, String sum_balance) {
        try {
            userInfoMapper.insert_financial(user_id,financial_number,financial_details,single_money,sum_balance);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("编辑失败"+e);
            return 0;
        }
    }

    //修改公司信息
    @Override
    public int update_companyinfo(CompanyInfo companyInfo) {
        try {
            userInfoMapper.update_companyinfo(companyInfo);
            return 1;
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("编辑失败"+e);
            return 0;
        }
    }


}
